package com.wems.farm_manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wems.farm_manage.domain.vo.DeptFarmMappingVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wems.common.annotation.Log;
import com.wems.common.core.controller.BaseController;
import com.wems.common.core.domain.AjaxResult;
import com.wems.common.enums.BusinessType;
import com.wems.farm_manage.domain.DeptFarmMapping;
import com.wems.farm_manage.service.IDeptFarmMappingService;
import com.wems.common.utils.poi.ExcelUtil;
import com.wems.common.core.page.TableDataInfo;

/**
 * 部门风场对应关系Controller
 * 
 * @author MPC
 * @date 2025-05-16
 */
@RestController
@RequestMapping("/deptFarmMapping/deptFarmMapping")
public class DeptFarmMappingController extends BaseController
{
    @Autowired
    private IDeptFarmMappingService deptFarmMappingService;

    /**
     * 查询部门风场对应关系列表
     */
    @PreAuthorize("@ss.hasPermi('deptFarmMapping:deptFarmMapping:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeptFarmMapping deptFarmMapping)
    {
        startPage();
        List<DeptFarmMappingVo> list = deptFarmMappingService.selectDeptFarmMappingVoList(deptFarmMapping);
        return getDataTable(list);
    }

    /**
     * 导出部门风场对应关系列表
     */
    @PreAuthorize("@ss.hasPermi('deptFarmMapping:deptFarmMapping:export')")
    @Log(title = "部门风场对应关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeptFarmMapping deptFarmMapping)
    {
        List<DeptFarmMapping> list = deptFarmMappingService.selectDeptFarmMappingList(deptFarmMapping);
        ExcelUtil<DeptFarmMapping> util = new ExcelUtil<DeptFarmMapping>(DeptFarmMapping.class);
        util.exportExcel(response, list, "部门风场对应关系数据");
    }

    /**
     * 获取部门风场对应关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('deptFarmMapping:deptFarmMapping:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deptFarmMappingService.selectDeptFarmMappingById(id));
    }

    /**
     * 新增部门风场对应关系
     */
    @PreAuthorize("@ss.hasPermi('deptFarmMapping:deptFarmMapping:add')")
    @Log(title = "部门风场对应关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeptFarmMapping deptFarmMapping)
    {
        return toAjax(deptFarmMappingService.insertDeptFarmMapping(deptFarmMapping));
    }

    /**
     * 修改部门风场对应关系
     */
    @PreAuthorize("@ss.hasPermi('deptFarmMapping:deptFarmMapping:edit')")
    @Log(title = "部门风场对应关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeptFarmMapping deptFarmMapping)
    {
        return toAjax(deptFarmMappingService.updateDeptFarmMapping(deptFarmMapping));
    }

    /**
     * 删除部门风场对应关系
     */
    @PreAuthorize("@ss.hasPermi('deptFarmMapping:deptFarmMapping:remove')")
    @Log(title = "部门风场对应关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deptFarmMappingService.deleteDeptFarmMappingByIds(ids));
    }
}
